package Dialog;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EndingDialog extends GobangDialog {
    public static int restart = 1;
    public static int back = 0;
    private JButton restartButton, backButton;
    private JLabel jLabel;

    /**
     * EndingDialog的构造函数
     *
     * @param jFrame
     * @param title  对话框标题
     * @param b
     */
    public EndingDialog(JFrame jFrame, String title, boolean b) {
        super(jFrame, title, b);
        this.init();
    }

    /**
     * 设置游戏结束弹窗标题
     *
     * @param winnerInfo 弹窗标题
     */
    public void setWinnerInfo(String winnerInfo) {
        jLabel.setText(winnerInfo);
    }

    /**
     * 初始化游戏结束选择对话框
     *
     * <p>初始化内容包括选项与内容</p>
     */
    private void init() {
        restartButton = new JButton("重新开始");
        backButton = new JButton("返回菜单");
        jLabel = new JLabel();

        this.setButtonStyle1(restartButton);
        this.setButtonStyle2(backButton);

        jLabel.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
        jLabel.setBounds(80, 10, 200, 100);

        add(restartButton);
        add(backButton);
        add(jLabel);
    }

    /**
     * 通过用户点击的按键来相应不同的事件
     *
     * <p>当用户点击重新开始时重新开始一局游戏
     * 当用户点击返回时返回初始菜单</p>
     *
     * @param e 用户点击的按键
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == restartButton) {
            message = restart;
            setVisible(false);
        } else if (e.getSource() == backButton) {
            message = back;
            setVisible(false);
        }
    }
}
